package com.app.utils
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.geom.Rectangle;

	public class Config
	{
		
		private static var _target:DisplayObject;
		private static var _width:Number;
		private static var _height:Number;
		private static var _gap:Number;
		
		public static function autoScale(target:DisplayObject ,width:Number ,height:Number ,gap:Number):void
		{
			_width = width;
			_height = height;
			_gap = gap;
			_target = target;
			
			_target.stage.addEventListener(Event.RESIZE ,scaleHandler);
			scaleHandler(null);
		}
		private static function scaleHandler(event:Event):void
		{
			var sx:Number = 1;
			var sy:Number = 1;
			var guiRect:Rectangle = new Rectangle(0 ,0 ,_width ,_height-_gap);
			var deviceRect:Rectangle = new Rectangle(0 ,0 
				,Math.min(_target.stage.stageWidth ,_target.stage.fullScreenWidth)
				,Math.min(_target.stage.stageHeight ,_target.stage.fullScreenHeight));
			
			if(deviceRect.width>deviceRect.height)
			{
				sx = sy = deviceRect.height/guiRect.height;
			}else{
				//等比 sx = sy = deviceRect.height/guiRect.height;
				sx = deviceRect.width/guiRect.width;
				sy = deviceRect.height/guiRect.height;
			}
			
			//单个缩放
			/*_top.scaleX = _main.scaleX = _navigator.scaleX = sx;
			_top.scaleY = _main.scaleY = _navigator.scaleY = sy;
			_top.y = _main.y = _navigator.y = -gap*sy;*/
			
			//整体绽放
			_target.scaleX = sx;
			_target.scaleY = sy;
			_target.y = -_gap*sy;
		}
	}
}